<div class="doc-item" id="doc-1294"><h2 class="doc-item-name">sample-mean<span class="namespace">(clojure.contrib.probabilities.monte-carlo)</span></h2><ul class="var-arglists"><li>(<span class="var-name">sample-mean</span> n dist)</li></ul><div class="var-docstring"><p>Return the distribution of the mean over n samples from the
       distribution dist</p></div><div class="var-source"><pre>; clojure/contrib/probabilities/monte_carlo.clj:181
(with-monad state-m

    (defn sample
      &quot;Return the distribution of samples of length n from the
       distribution dist&quot;
      [n dist]
      (m-seq (replicate n dist)))

    (defn sample-reduce
      &quot;Returns the distribution of the reduction of f over n samples from the
       distribution dist.&quot;
      ([f n dist]
	 (if (zero? n)
	   (m-result (f))
	   (let [m-f    (m-lift 2 f)
		 sample (replicate n dist)]
	     (reduce m-f sample))))
      ([f val n dist]
	 (let [m-f    (m-lift 2 f)
	       m-val  (m-result val)
	       sample (replicate n dist)]
	   (reduce m-f m-val sample))))

    (defn sample-sum
      &quot;Return the distribution of the sum over n samples from the
       distribution dist.&quot;
      [n dist]
      (sample-reduce ga/+ n dist))

    (defn sample-mean
      &quot;Return the distribution of the mean over n samples from the
       distribution dist&quot;
      [n dist]
      (let [div-by-n (m-lift 1 #(ga/* % (/ n)))]
	(div-by-n (sample-sum n dist))))

    (defn sample-mean-variance
      &quot;Return the distribution of the mean-and-variance (a vector containing
       the mean and the variance) over n samples from the distribution dist&quot;
      [n dist]
      (let [extract (m-lift 1 (fn [mv] [(:mean mv) (:variance mv)]))]
	(extract (sample-reduce acc/add acc/empty-mean-variance n dist))))

)</pre></div><div class="license"><p>Copyright (c) Rich Hickey. All rights reserved.</p><p>The use and distribution terms for this software are covered by the <a href="http://opensource.org/licenses/eclipse-1.0.php">Eclipse Public License 1.0</a>, which can be found in the file
          epl-v10.html at the root of this distribution. By using this software
          in any fashion, you are agreeing to be bound by the terms of this
          license. You must not remove this notice, or any other, from this
          software.</p></div></div>